﻿using System.Linq.Expressions;
using K9Nano.Domain.Entities;

namespace K9Nano.Application.Dtos;

public interface IPagedQueryDto
{
    int PageIndex { get; set; }
    int PageSize { get; set; }
    int Skip();
}

public class PagedQueryDto : IPagedQueryDto
{
    public int PageIndex { get; set; } = 1;

    public int PageSize { get; set; } = 10;

    public int Skip() => (PageIndex - 1) * PageSize;
}

public interface IPagedQueryDto<TEntity>
    where TEntity : class, IEntity
{
    Expression<Func<TEntity, bool>>? GetPredicate();
    IQueryable<TEntity> Sort(IQueryable<TEntity> query);
}

public class PagedQueryDto<TEntity> : PagedQueryDto, IPagedQueryDto<TEntity>
    where TEntity : class, IEntity
{
    public virtual Expression<Func<TEntity, bool>>? GetPredicate()
    {
        return null;
    }

    public virtual IQueryable<TEntity> Sort(IQueryable<TEntity> query)
    {
        return query.OrderByDescending(a => a.Id);
    }
}
